package org.ziletech.service.impl;

import java.io.Serializable;
import java.sql.Connection;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.executor.BatchResult;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.ziletech.service.BaseService;

@Component
public class BaseServiceImpl<T,PK extends Serializable> extends SqlSessionTemplate implements BaseService<T,PK>  {
	private Class<T> persistentClass;
	@Autowired
	private static SqlSessionFactory sqlSessionFactory;
	/**
	 * 通过构造函数让对应的service操作对应的实体类
	 * 通过继承该类实现
	 * @param 实体类
	 * @author tonyli
	 */
	public BaseServiceImpl(final Class<T> persistentClass) {
		super(sqlSessionFactory);
		this.persistentClass = persistentClass;

	}
	public Class<T> getPersistentClass() {
		return persistentClass;
	}
	public void setPersistentClass(Class<T> persistentClass) {
		this.persistentClass = persistentClass;
	}
	public <T> T selectOne(String statement) {
		return super.selectOne(statement);
	}
	public <T> T selectOne(String statement, Object parameter) {
		return super.selectOne(statement,parameter);
	}
	public <E> List<E> selectList(String statement) {
		return super.selectList(statement);
	}
	public <E> List<E> selectList(String statement, Object parameter) {
		return super.selectList(statement,parameter);
	}
	public <E> List<E> selectList(String statement, Object parameter,
			RowBounds rowBounds) {
		return super.selectList(statement,parameter,rowBounds);
	}
	public <K, V> Map<K, V> selectMap(String statement, String mapKey) {
		return super.selectMap(statement,mapKey);
	}
	public <K, V> Map<K, V> selectMap(String statement, Object parameter,
			String mapKey) {
		return super.selectMap(statement,parameter,mapKey);
	}
	public <K, V> Map<K, V> selectMap(String statement, Object parameter,
			String mapKey, RowBounds rowBounds) {
		return super.selectMap(statement,parameter,mapKey,rowBounds);
	}
	public void select(String statement, Object parameter, ResultHandler handler) {
		super.select(statement,parameter,handler);	
	}
	public void select(String statement, ResultHandler handler) {
		super.select(statement,handler);
	}
	public void select(String statement, Object parameter, RowBounds rowBounds,
			ResultHandler handler) {
		super.select(statement,parameter,rowBounds,handler);
	}
	public int insert(String statement) {
		return super.insert(statement);
	}
	public int insert(String statement, Object parameter) {
		return super.insert(statement,parameter);
	}
	public int update(String statement) {
		return super.update(statement);
	}
	public int update(String statement, Object parameter) {
		return super.update(statement,parameter);
	}
	public int delete(String statement) {
		return super.delete(statement);
	}
	public int delete(String statement, Object parameter) {
		return super.delete(statement,parameter);
	}
	public void commit() {
		super.commit();
	}
	public void commit(boolean force) {
		super.commit(force);
	}
	public void rollback() {
		super.rollback();
	}
	public void rollback(boolean force) {
		super.rollback(force);
	}
	public List<BatchResult> flushStatements() {	
		return super.flushStatements();
	}
	public void close() {
		super.close();
	}
	public void clearCache() {
		super.clearCache();
	}
	public <T> T getMapper(Class<T> type) {
		return super.getMapper(type);
	}
}
